/*
 *  IIS.h
 *  TubeTruck
 *
 *  Created by Aeturnum on 6/4/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#pragma once

#include <vector>
#include <exception>
#include <stdio.h>

#include "Packet.h"
#include "util.h"
#include "TubeTruckTypes.h"
#include "smartalloc_wrap.h"
#include "RSA.h"
#include "Hashing.h"
#include "Group.h"

namespace TTP {
   class IIS : public Packet , public Crypt::Hashing {
   protected:
      uint32_t mDestHash;
      std::vector<byte> mPubKey;
      byte mGroupCount;
      std::vector< std::vector<byte> > mMulticastAddrs, mGroupKeys;
      unsigned short mAppDataLength;
      std::vector<byte> mAppData;
      
      enum {IIS_mcastAddrLength = 16};
      
   public:
      IIS();
      IIS(id_hash);
      IIS(id_hash, std::vector<byte>&, std::vector< std::vector<byte> >&, std::vector< std::vector<byte> >&);
      IIS(id_hash, std::vector<byte>&, std::vector< std::vector<byte> >&, std::vector< std::vector<byte> >&, std::vector<byte>&);
      ~IIS();
      
      // accessors
      std::vector<byte> getPubKey() const;
      byte getGroupcount() const;
      std::vector<byte> getMcastAddr(byte n) const;
      std::vector<byte> getGroupKey(byte n) const;
      std::vector< std::vector<byte> > getMcastAddrs() const;
      std::vector< std::vector<byte> > getGroupKeys() const;
      unsigned short getAppDataLength() const;
      std::vector<byte> getAppData() const;
      
      // modifiers
      void setPubKey(std::vector<byte>&);
      void addMulticastGroup(std::vector<byte>&, std::vector<byte>&);
      void addMulticastGroup(Group&);
      void addAppData(std::vector<byte>&);
      
      // idhash
      void  setSourceIdHash(id_hash);
      id_hash getSourceIdHash() const;
      void  setDestIdHash(id_hash);
      id_hash getDestIdHash() const;
      
      // inherited
      void fromVec(std::vector<byte>::const_iterator &vit, 
       const std::vector<byte>::const_iterator &end);
      void toVec(std::vector<byte> &vec) const;
      
      std::vector<byte> getHashablePacket() const;
   };
}
